<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>商家提现</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
	</head>

	<body onload="check_verif()">
		<form id="my_form"  class="layui-form update_form" action="" method="post">
			<div class="layui-form-item">
				<label class="layui-form-label">提现金额</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="money" lay-verify="chekc_money" id="tixian_money" placeholder="输入提现金额,可提现：{$data.balance}" autocomplete="off" class="layui-input" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">提现时间</label>
				<div class="layui-input-block" style="float: left; margin-right: 20px; margin-left: 0;">
					<div class="layui-form-item" style="border-bottom: 1px solid #ebdfdf;">
					    <div class="layui-input-block" style="margin-left: 50px;">
					      <input type="radio" name="withdraw_type" value="1" title="D+0 结算费率:0.2%">
					    </div>
					</div>
					<div class="layui-form-item" style="border-bottom: 1px solid #ebdfdf;">
					    <div class="layui-input-block" style="margin-left: 50px;">
					      <input type="radio" name="withdraw_type" value="2" title="T+2 结算费率:0.1%" checked>
					    </div>
					</div>
					<div class="layui-form-item" style="border-bottom: 1px solid #ebdfdf;">
					    <div class="layui-input-block" style="margin-left: 50px;">
					      <input type="radio" name="withdraw_type" value="3" title="T+7 结算费率:0">
					    </div>
					</div>
				</div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">手续费</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="sxf_money" id="sxf_money" value="0.00" disabled="disabled" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item update_btnbox" style="text-align: center;margin-left:unset">
				<div class="layui-input-block" style="max-width: unset;float: unset;">
					<button  id='change_but' class="layui-btn" lay-submit lay-filter="demo1">确定提现</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</body>
</html>
<script>
    //提交表单
	function set_content(){
  		 $.ajax({
             	type:"post",
                url:"{:url('finace/tixian_add')}",
                data: $('#my_form').serialize(),
                success:function(data){
                    layer.msg(data.msg, {
						  icon: 1,
						  time: 1500 //2秒关闭（如果不配置，默认是3秒）
						}, function(){
							if(data.code == 200){
								parent.location.reload();
							}
					});
                }
        });
  		
  	}
	
	
	//图片上传
	layui.use(['form'], function(){
  		var $ = layui.jquery,form = layui.form;
	  
	  	form.verify({
			chekc_money: function(value, item){ //value：表单的值、item：表单的DOM对象
			  	var user_money = "{$data['balance']}";
			    if(value>  parseInt(user_money)){
			      return '余额不足';
			    }
			    
			    if(value<100){
			    	return '单次提现金额不能小于100元';
			    }
			}
		}); 
	  
	  
	  	//监听提交
		form.on('submit(demo1)', function(data){
			$('#change_but').addClass("layui-btn-disabled");
			set_content();
			return false;
		});
	})
	
	function check_verif(){
		$.ajax({
			type:"post",
			url: "{:url('index/get_verif')}",
			data: {},//表单数据
			success: function(data) {
				if(data.code != 200){
					layer.msg("认证未通过", {
					  icon: 1,
					  time: 1000 //2秒关闭（如果不配置，默认是3秒）
					}, function(){
						  if(data.code != 200) {
						  		parent.location ="{:url('index/verif')}";
						  }
					});
				}
			}
		})
	}
	
	$("#tixian_money").keyup(function(){
		
		var sxf_money = 0.00;
		var tx_type =  $('input:radio[name="withdraw_type"]:checked').val();
		
		
		if(typeof parseInt($("#tixian_money").val())  == "number"){
			
			if(tx_type == 1){
				sxf_money = parseFloat(0.0002)*1000*$("#tixian_money").val()/1000;
			}else if(tx_type == 2){
				sxf_money = parseFloat(0.0001)*1000*$("#tixian_money").val()/1000;
			}
			
			if(parseFloat(sxf_money)<0.01){
				sxf_money = 0.01;
			}else{
				sxf_money = sxf_money.toFixed(2);
			}
			
			$("#sxf_money").val(sxf_money);
		}
	});
</script>
